<?PHP
require_once('config.inc.php');
require_once('database.inc.php');
require_once('functions.inc.php');
require_once(LIBRARY_PATH.'json/JSON.php');

session_start();
$db = LinkDB();
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);

//响应注销操作
if( @$_POST['logout'] == 'true' )
{
 	unset( $_SESSION['userName'] );
	unset( $_SESSION['userid'] );
	die ($json->encode(array(
		'isLogin'=> false,
		'message'=> '注销成功'
	)));
}
//响应登陆操作
if(@$_POST['username'] != null && @$_POST['password'] != null ) {
	$username = $_POST['username'];
	$password = $_POST['password'];
	if ($username != 'administrator' || $password != 'listCtrl') {
		die ($json->encode(array(
			'isLogin'=> false,
			'message'=> '用户名或密码不正确'
		)));
	}
	$_SESSION['userName'] = $username;
	$_SESSION['popedom'] = array(
		'linkman'=>array(
			array(
				'allow'=> true,
				'name' => 'create',
				'text' => '创建'
			),
			array(
				'allow'=> true,
				'name' => 'edit',
				'text' => '编辑'
			),
			array(
				'allow'=> true,
				'name' => 'delete',
				'text' => '删除'
			)
		)
	);
//响应获取信息操作
}elseif (!isset($_SESSION['userName']) || !isset($_SESSION['popedom'])) {
	die ($json->encode(array(
		'isLogin'=> false,
		'message'=> '用户未登陆'
	)));
}
//输出用户信息
die ($json->encode(array(
	'isLogin' => true,
	'username'=> $_SESSION['userName'],
	'popedom' => $_SESSION['popedom']
)));
/**
 * 数据模板
{
	isLogin  : true,
	username : '测试用户',
	popedom  : {
		'linkman': [
			{allow : true,
			 name  : 'create',
			 text  : '创建新联系人'},

			{allow : true,
			 name  : 'edit',
			 text  : '编辑'},

			{allow : true,
			 name  : 'delete',
			 text  : '删除'}
		]
	}
}
 */
?>